package Model;
import Presenter.Map;
import Presenter.Round;

enum Difficulty {
	BEGINNER, STANDARD, TOURNAMENT
}

enum MapType {
	STANDARD, RANDOM
}
/**
 * 
 * @author Matthew
 * Constructs an instance of the game.  Holds the players,
 * As well as information about the game such as map type,
 * and difficulty
 *
 */

public class Game {

	public Difficulty difficulty;

	private MapType mapType;

	private int playerCount;

	private int humanPlayerCount;

	private int currentRound;

	private int totalRounds;

	public static Player player1;

	public static Player player2;

	public static Player player3;

	public static Player player4;

	private Player[] players;

	private Map map;
	
	private Round round;
	
	private Store store;
	/**
	 * @author Philip
	 * @param none
	 * @return none
	 * Constructs  the game object.
	 */
	public Game() {
		players = new Player[4];
		player1 = new Player();
		player2 = new Player();
		player3 = new Player();
		player4 = new Player();
		players[0] = player1;
		players[1] = player2;
		players[2] = player3;
		players[3] = player4;
		difficulty = Difficulty.BEGINNER;
		mapType = MapType.STANDARD;
		playerCount = 4;
		humanPlayerCount = 4;
		currentRound = 1;
		totalRounds = 12;
		map = new Map();
		map.setDefaultMap();
		store = new Store();
	}
	/**
	 * @author Philip
	 * begins turns in a given round
	 */
	public void initializeRound() {

	}
	/**
	 * @author Matthew
	 * @return returns an array of all the players in the game
	 * 
	 */
	public Player[] getPlayers() {
		return players;
	}
	
	/**
	 * getter for store
	 */
	public Store getStore() {
		return store;
	}
	/**
	 * @author Matthew
	 * @param players
	 * sets the individual player objects to the parts of an array
	 */
	public void setPlayers(Player[] players) {
		this.players = players;
		player1 = players[0];
		player2 = players[1];
		player3 = players[2];
		player4 = players[3];
	}
	/**
	 * 
	 * @return Difficulty enum
	 * returns the difficulty setting
	 */
	public Difficulty getDifficulty() {
		return difficulty;
	}
	/**
	 * sets the difficulty of the game
	 * @param difficulty
	 */
	public void setDifficulty(Difficulty difficulty) {
		this.difficulty = difficulty;
	}

	/**
	 * sets the difficulty of the game to beginner
	 * @param difficulty
	 */
	public void setDifficultyBeginner() {
		this.difficulty = difficulty.BEGINNER;
	}

	/**
	 * sets the difficulty of the game to standard
	 * @param difficulty
	 */
	public void setDifficultyStandard() {
		this.difficulty = difficulty.STANDARD;
	}

	/**
	 * sets the difficulty of the game to tournament
	 * @param difficulty
	 */
	public void setDifficultyTournament() {
		this.difficulty = difficulty.TOURNAMENT;
	}
	
	/**
	 * @returns the maptype
	 * @return MapType
	 */

	public MapType getMapType() {
		return mapType;
	}
	/**
	 * sets the mapType
	 * @param mapType
	 */
	public void setMapType(MapType mapType) {
		this.mapType = mapType;
		System.out.println("setting map type");
		map.setDefaultMap();
	}
	
	/**
	 * sets the mapType to Random
	 * @param mapType
	 */
	public void setMapTypeRandom() {
		this.mapType = mapType.RANDOM;
		System.out.println("setting map type");
		map.setDefaultMap();
	}
	
	/**
	 * sets the mapType to Standard
	 * @param mapType
	 */
	public void setMapTypeStandard() {
		this.mapType = mapType.STANDARD;
		System.out.println("setting map type");
		map.setDefaultMap();
	}
	
	/**
	 * Returns the current Player count
	 * @return int playerCount
	 */
	public int getPlayerCount() {
		return playerCount;
	}

	/**
	 * sets the player count
	 * @param playerCount
	 */
	public void setPlayerCount(int playerCount) {
		this.playerCount = playerCount;
	}

	/**
	 * Returns the number of human players
	 * @return int humanPlayerCount
	 */
	public int getHumanPlayerCount() {
		return humanPlayerCount;
	}
	/**
	 * sets the number of human players
	 * @param humanCount
	 */
	public void setHumanPlayerCount(int humanCount) {
		this.humanPlayerCount = humanCount;
	}

	/**
	 * gets the current round number
	 * @return int currentRound
	 */
	public int getCurrentRound() {
		return currentRound;
	}
	/**
	 * sets the current round of the of the game
	 * @param currentRound
	 */
	public void setCurrentRound(int currentRound) {
		this.currentRound = currentRound;
	}

	/**
	 * gets the total number of rounds for the game
	 * @return int totalRounds
	 */
	public int getTotalRounds() {
		return totalRounds;
	}
	/**
	 * sets the total number of rounds
	 * @param totalRounds
	 */
	public void setTotalRounds(int totalRounds) {
		this.totalRounds = totalRounds;
	}
	/**
	 * Returns the map instance;
	 * @return Map map
	 */
	public Map getMap() {
		return map;
	}
	/**
	 * Assigns an owner to a specific tile.
	 * @param player
	 * @param tile
	 */
	public void setOwner(Player player, Tile tile) {
		tile.setOwner(player);
	}
		
	/**
	 * Increments the currentRound counter
	 */
	public void incrementRound() {
		currentRound = currentRound + 1; 
	}

	/**
	 * @description: returns true if 2 players have the same color. False otherwise
	 * @return boolean: whether or not a duplicate color exists.
	 */
	public boolean duplicateColors()
	{
		for (int i=0; i<players.length; i++)
		{
			for (int j=i+1; j<players.length; j++)
			{

				if ( players[i].getColor() == players[j].getColor() )
				{
					return true;
				}
			}
		}

		return false; //otherwise no duplicates

	}
	
	/**
	 * Returns difficulty level as a string.
	 * @return difficultyLevel
	 */
	public String getDifficultyString() {
		if(difficulty.equals(difficulty.BEGINNER)) {
			return "BEGINNER";
		} else if(difficulty.equals(difficulty.STANDARD)){
			return "STANDARD";
		} else {
			return "TOURNAMENT";
		}
	}
	
	/**
	 * Sets difficulty according to string input.
	 * @param diff
	 */
	public void setDifficultyString(String diff) {
		if(diff.equals("BEGINNER")){
			difficulty = Difficulty.BEGINNER;
		} else if(diff.equals("STANDARD")) {
			difficulty = difficulty.STANDARD;
		} else {
			difficulty = difficulty.TOURNAMENT;
		}
	}
	
	/**
	 * Returns the map type as a string
	 * @return mapTypeString;
	 */
	public String getMapTypeString() {
		if(mapType.equals(MapType.RANDOM)){
			return "RANDOM";
		} else return "STANDARD";
	}
	
	/**
	 * Sets the map type according to string input.
	 * @param mapString
	 */
	public void setMapTypeString(String mapString) {
		if(mapString.equals("RANDOM")){
			mapType = MapType.RANDOM;
		} else {
			mapType = MapType.STANDARD;
		}
	}
}
